#coding:utf-8
from django.db import models
from django.utils import timezone
from lovewith.account.models import MtUser


#请柬
class Card(models.Model):
    title = models.CharField(max_length=255, verbose_name=u'请柬标题')
    map_point = models.CharField(max_length=64, verbose_name=u'地图坐标')
    content = models.TextField(verbose_name=u'邀请语')
    '''
    标准json格式
    config = {
        //信封图片地址
        "envelope": "url",
        "content" : {
            //内衬图片地址
            "url": "",
            //坐标点
            "coords": {
                //坐标[x,y] 尺寸[w, h]
                "bride": {"x": 10, "y": 20, "w": 100, "h":34}
            }
        },
        //邮票地址
        "stamp": ""
    }
    '''
    card_config = models.TextField(verbose_name=u'请柬配置')
    add_date = models.DateTimeField(default=timezone.now, verbose_name=u'请柬创建时间')
    #所有人可见：1  仅邀请者可见： 2
    permission =  models.SmallIntegerField(max_length=1, default=2, verbose_name=u'权限')
    user = models.ForeignKey(MtUser, verbose_name=u'创建者')

    def __unicode__(self):
        return self.bride

    class Meta:
        verbose_name = u'请柬'
        db_table = 'mt_card'


#请柬内页
class CardPost(models.Model):
    card = models.ForeignKey(Card, verbose_name=u'请柬')
    title = models.CharField(max_length=255, verbose_name=u'标题')
    content = models.TextField(blank=True, verbose_name=u'内容')
    media = models.CharField(max_length=255, blank=True, verbose_name=u'图片')
    user = models.ForeignKey(MtUser, verbose_name=u'user')
    post_data = models.DateTimeField(default=timezone.now, verbose_name=u'发布时间')

    def __unicode__(self):
        return self.title

    class Meta:
        verbose_name = u'请柬'
        db_table = 'mt_card_post'


'''
请柬邀请用户
'''
class CardInvite(models.Model):
    card = models.ForeignKey(Card, verbose_name=u'请柬')
    user_id = models.CharField(max_length=50, verbose_name=u'被邀请者id')
    user_name = models.CharField(max_length=50, verbose_name=u'被邀请者姓名')
    user_email = models.CharField(max_length=50, verbose_name=u'被邀请者邮箱')
    # email: 1  tqq:2  weibo: 3
    invite_type = models.CharField(max_length=10, verbose_name=u'邀请方式')
    is_send = models.SmallIntegerField(max_length=1, default=0, verbose_name=u'是否已发送')


    def __unicode__(self):
        return self.username

    class Meta:
        verbose_name = u'请柬'
        db_table = 'mt_card_invite'

